<script type="text/html" template>
  <link rel="stylesheet" href="{{ layui.setter.base }}style/css/reset.css">
  <link rel="stylesheet" href="{{ layui.setter.base }}style/css/patrol/index.css">
  <link rel="stylesheet" href="{{ layui.setter.base }}style/page.css">
</script>
<style scoped>
.newProjectBtn{
  width: auto;
  font-size: 11px;
  margin: 0;
  padding: 0 5px;
  border: 0;
  text-align: center;
}
#layui-layer2 {
  height:auto;
}
</style>
<div class="box-box">
  <div class="boxQuery">
      <ul class=" layui-row">
          <li class="layui-col-md4 layui-col-sm4">
              <div style="margin-right: 23px;">公司：<input type="text"></div>
              <div>工单名称：<input type="text"></div>
              <div>工单编号：<input type="text"></div>
          </li>
          <li class="layui-col-md4 layui-col-sm4">
              <div style="margin-right: 103px;"> 巡检计划：
                  <select>
                      <option value=""></option>
                      <option value="H">时</option>
                      <option value="D">日</option>
                      <option value="W">周</option>
                      <option value="M">月</option>
                  </select>
              </div>
              <div>巡检人：<input type="text"></div>
              <div style="margin-left: 10px;">巡检时间：<input type="text" id="time"></div>
          </li>
          <li class="layui-col-md4 layui-col-sm4">
              <div>位置范围：<input type="text"></div>
              <div>设备编号：<input type="text"></div>
              <div style="margin-right: 90px;">工单状态：
                  <select class="fil05">
                      <option value=""></option>
                      <option value="1">未开始</option>
                      <option value="2">待执行</option>
                      <option value="9">已完成</option>
                  </select>
              </div>
          </li>

      </ul>
      <div class="footer layui-btn-container" style="justify-content: center">

          <button class="sure layui-btn layui-btn-radius layui-btn-primary">
              确定
          </button>
          <button class="close layui-btn layui-btn-radius layui-btn-primary">
              关闭
          </button>
          <button class="reset layui-btn layui-btn-radius layui-btn-primary">
              清空
          </button>
      </div>
  </div>

  <div class="box layui-fluid layui-row">

      <!-- 查询按钮 -->
      <div class="btn-box layui-btn-container layui-row" style="padding: 0 5px;">
          <button class="btn3 layui-btn layui-btn-radius layui-btn-primary"
              style="margin-right: 10px;background-color: #CCDAE3;">
              <i class=" layui-icon layui-icon-add-circle" style="font-size: 14px; color: #4BA4FE;"></i>
              <span style="color:#666666;">创建工单</span>
          </button>
          <button class="btn2 layui-btn layui-btn-radius layui-btn-primary">
              <i class="layui-icon layui-icon-add-circle" style="font-size: 14px; color: #FFF;"></i>
              <span>转单</span>
          </button>
          <button style="width: 80px;background: orangered;"
              class="search layui-btn layui-btn-radius layui-btn-primary layui-col-sm6 layui-col-md6">
              <i class="layui-icon layui-icon-search" style="font-size: 10px; color: #FFF;"></i>
              <span>条件查询</span>
          </button>
      </div>

      <table id="inspectionSheet" lay-skin='nob' lay-filter="inspectionSheet" lay-even></table>

      <div class="footer layui-btn-container">
          <button class="btn1 layui-btn layui-btn-radius layui-btn-primary" style="background:#FF4C4C;">
              <i class="layui-icon layui-icon-delete" style="font-size: 14px; color: #FFF;"></i>
              <span>删除</span>
          </button>
      </div>
  </div>
</div>

</body>
<script>
  var tableArray = []
    layui.use(['form', 'table', 'api', 'utill', 'laydate', 'jquery'], function () { //此段代码必不可少
      var table = layui.table,
          setter = layui.setter,
          laytpl = layui.laytpl,
          api = layui.api,
          utill = layui.utill,
          form = layui.form,
          admin = layui.admin,
          view = layui.view,
          element = layui.element,
          form = layui.form,
          $ = layui.jquery,
          laydate = layui.laydate;
          laydate.render({
    elem: "#time" //指定元素
  });
  table.on("tool(inspectionSheet)", function (obj) {
    //tcReqId
    if (obj.data.fil05 == 2 || obj.data.fil05 == 1 || obj.data.fil05 == 7 || obj.data.fil05 == 0) {
      $(this).attr("lay-href", `patrol/popup/create_work#?id=${obj.data.tcReqId}`);
    } else if (obj.data.fil05 == 9 || obj.data.fil05 == 8) {
      $(this).attr("lay-href", `patrol/popup/keep#?id=${obj.data.tcReqId}`);
    }

  });

  // 高查弹窗关闭
  $(".close").on("click", function () {
    $(".boxQuery").css("display", "none");
  });

  // 高查清空
  $(".reset").on("click", function () {
    $(this)
      .parent()
      .prev()
      .find("input")
      .val("")
      .parents("ul")
      .find("select")
      .val("");
  });
  // 高查查询
  $(".sure").on("click", function () {
    let params = {};
    let azp02 = $(".boxQuery")
      .find("input")
      .eq(0)
      .val(); // 公司
    let tc_req_name = $(".boxQuery")
      .find("input")
      .eq(1)
      .val(); // 工单名称
    let fil01 = $(".boxQuery")
      .find("input")
      .eq(2)
      .val(); // 工单编号
    let tc_plan_frequency = $(".boxQuery")
      .find("select")
      .val(); // 巡检计划
    let gen02 = $(".boxQuery")
      .find("input")
      .eq(3)
      .val(); // 巡检人
    let fil12 = $(".boxQuery")
      .find("input")
      .eq(4)
      .val(); // 巡检时间
    let fil07 = $(".boxQuery")
      .find("input")
      .eq(5)
      .val(); // 位置范围
    let tc_detail_fia01a = $(".boxQuery")
      .find("input")
      .eq(6)
      .val(); // 设备编号
    let fil05 = $(".boxQuery")
      .find(".fil05")
      .val(); // 工单状态

    if (azp02) params["azp02"] = azp02;
    if (tc_req_name) params["tc_req_name"] = tc_req_name;
    if (fil01) params["fil01"] = fil01;
    if (tc_plan_frequency) params["tc_plan_frequency"] = tc_plan_frequency;
    if (gen02) params["gen02"] = gen02;
    if (fil12) params["fil12"] = fil12;
    if (fil07) params["fil07"] = fil07;
    if (tc_detail_fia01a) params["tc_detail_fia01a"] = tc_detail_fia01a;
    if (fil05) params["fil05"] = fil05;
    utill.columnCustom('#inspectionSheet', "FilFileXJAndBYVO", {
      url: api.host + "/order/selectListByParam.json",
      where: {
        azp02: azp02,
        tc_req_name: tc_req_name,
        fil01: fil01,
        tc_plan_frequency: tc_plan_frequency,
        gen02: gen02,
        fil12: fil12,
        fil07: fil07,
        tc_detail_fia01: tc_detail_fia01a,
        fil05: fil05
      }, templet: _TPL
    });
    reload(inspectionSheet, params);
    $(".boxQuery").css("display", "none");
  });

  // 高查
  $(".search").on("click", function () {
    $(".boxQuery").css("display", "block");
  });

  // 创建工单
  $(".btn3").on("click", function () {
    $(this).attr("lay-href", "patrol/popup/update_work");
  });

  // 转单
  $(".btn2").click(function () {
    tableArray = table.checkStatus("#inspectionSheet").data;
    if (tableArray.length == 0) return layer.msg("请选择一条数据");
    if (tableArray.length > 1) return layer.msg("只能操作一条数据");
    admin.popup({
            title: '转单',
            area: ['394px', '340px'],
            id: 'changeorder',
            success: function (layero, index) {
                view(this.id).render('patrol/popup/changeOrder')
                    .done(function () {
                        $('.inner').eq(0).val(tableArray[0].gen02)
                        $('.inner').eq(1).val(tableArray[0].fil13)
                        form.on('submit(LAY-submit-qd)', function (data) {
                              let params = {
                                  filuser: $('#gen02').val(),
                                  id: tableArray[0].tcReqId,
                                  fil13: data.field.fil13
                                  }
                                admin.req({
                                    url: api.host + '/order/giveOrder.json',
                                    type: "post",
                                    data: JSON.stringify(params),
                                    dataType: 'json',
                                    contentType: 'application/json',
                                    done: function (res) {
                                        if(res.code=='0'){
                                            layer.msg(res.message);
                                            layui.table.reload('#inspectionSheet');
                                            layer.closeAll();
                                        }else{
                                            layer.msg(res.message);
                                        }
                                        
                                }
                            });
                        })
                    });
            }
        });
  });

  var _TPL = {
    fil05: function (d) {
      if (d.fil05 == 1) {
        return "<span>未开始</span>";
      }else if (d.fil05 == 0) {
        return "<span style='color:blue'>未提交</span>";
      } else if (d.fil05 == 2) {
        return "<span style='color:blue'>待执行</span>";
      } else if (d.fil05 == 7) {
        return "<span style='color:red'>超时</span>";
      } else if (d.fil05 == 8) {
        return "<span style='color:orange'>超时完成</span>";
      }
      else if (d.fil05 == 9) {
        return "<span style='color:green'>已完成</span>";
      }
    },
    tcReqIsunpln: function (d) {
      if (d.tcReqIsunpln == 0) {
        return "<span>是</span>";
      } else if (d.tcReqIsunpln == 1) {
        return "<span>否</span>";
      }
    },
    tcPlanFrequency(d){
      if(d.tcPlanFrequency == 'D'){
        return '<div>日检</div>'
      }else if(d.tcPlanFrequency == 'W'){
        return '<div>周检</div>'
      }else if(d.tcPlanFrequency == 'M'){
        return '<div>月检</div>'
      }else{
        return '<div>小时</div>'
      }
    }
  };
  // 列定制
  utill.columnCustom('#inspectionSheet', "FilFileXJAndBYVO", {
    url: api.host + "/order/selectListByParam.json",
    cellMinWidth: 120,
    templet: _TPL,
  });

  //是否隐藏转单按钮
  utill.showAndHide('.btn2', 'PollingOrderController:IgiveOrder');
  utill.showAndHide('.btn3', 'PollingOrderController:insertPollingOrder');
  utill.showAndHide('.btn1', 'PollingOrderController:submitXJ');


  var arrs = [];
  table.on("checkbox(inspectionSheet)", function (obj) {
    api1 = api;
  });

  // 批量删除
  $(".btn1").click(function () {
    var arrs_llps = [];
    var checkStatus = table.checkStatus('#inspectionSheet');

    if (checkStatus.data.length == 0) {
      layer.msg('请至少选择一条要删除的数据', { icon: 2 });
      return;
    }
    for (var i = 0; i < checkStatus.data.length; i++) {
      arrs_llps.push(checkStatus.data[i].tcReqId);
    }

    var obj = {
      "tcReqId": arrs_llps
    }
    layer.confirm('真的删除吗？', function (index) {
      admin.req({
        type: 'post',
        dataType: 'json',
        contentType: 'application/json',
        url: api.host + api.delFilFilexj_llp,
        data: JSON.stringify(obj),
        success: function (data) {
          layer.msg(data.message);
          layui.table.reload('#inspectionSheet'); //重载表格  
          //layer.close(index); //执行关闭 
        }
      });
    })
    // 请求
   
  });
      });
</script>

<style>
  .box-box {
      position: relative;
  }

  .box .layui-form {
      position: relative;
  }

  .box .layui-table-tool-self {
      top: 5px;
  }

  .box .layui-table-tool {
      position: static;
      min-height: 0;
      padding: 0;
      line-height: 0;
      position: absolute;
  }

  .boxQuery {
      display: none;
      z-index: 999;
      top: 0;
      position: absolute;
      width: 100%;
      background-color: #ffffff;
      margin: 0 auto;
      text-align: left;
      overflow: hidden;
  }

  .boxQuery li {
      padding: 19px 17px 16px;
      font-size: 11px;
      color: #616161;
      float: left;
      text-align: center;
  }

  .boxQuery div {
      margin-bottom: 10px;
      margin-top: 5px;
  }

  .sure {
      width: 70px;
      height: 25px;
      font-size: 11px;
      border-radius: 15px;
      background-color: #FF4C4C;
  }

  .close {
      width: 70px;
      height: 25px;
      border-radius: 15px;
      background-color: #3D8CC9;
  }

  .reset {
      width: 70px;
      height: 25px;
      border-radius: 15px;
      background-color: #FF9F0C;
  }
  .layui-layer-iframe iframe,#layui-layer2{
         height: 300px;
     }
</style>